Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic fields #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

fehays
Copy link
Contributor

@fehays fehays commented May 4, 2020

Reference:
TYPEOF SOQL Reference

Polymorphic Relationships (TYPEOF)

String query = new Q(Event.SObjectType)
    .selectFields(Q.typeOf('What')
        .when('Account').then(new Set<String> {'Phone', 'NumberOfEmployees'})   
        .when('Opportunity').then(new Set<String> {'Amount', 'CloseDate'})                 
        .otherwise(new Set<String> {'Name', 'Email'})
    );
    
System.debug(query.build());
/*
SELECT
    TYPEOF What
    WHEN Account THEN Phone,NumberOfEmployees
    WHEN Opportunity THEN Amount,CloseDate
    ELSE Name,Email
    END
FROM Event
*/

@fehays fehays marked this pull request as ready for review May 4, 2020 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant